//! Easy HTTP Proxy Server
//! 
//! A simple HTTP/HTTPS proxy server with connection pooling support.
//! 
//! # Examples
//! 
//! ```no_run
//! use easy_http_proxy_server::{ProxyServer, ProxyConfig};
//! use std::net::SocketAddr;
//! 
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let addr: SocketAddr = "127.0.0.1:3128".parse()?;
//!     let config = ProxyConfig::new(addr, true);
//!     let server = ProxyServer::new(config);
//!     
//!     println!("Starting proxy server on {}", addr);
//!     server.run().await?;
//!     
//!     Ok(())
//! }
//! ```

use easy_http_proxy_server::{ProxyServer, ProxyConfig};
use clap::Parser;
use std::net::SocketAddr;
use log::info;

#[derive(Parser, Debug)]
#[command(name = "easy-http-proxy-server")]
#[command(about = "A simple HTTP/HTTPS proxy server with connection pooling", long_about = None)]
struct Args {
    /// Host address to bind to
    #[arg(long, default_value = "127.0.0.1")]
    host: String,

    /// Port to listen on
    #[arg(short, long, default_value = "3128")]
    port: u16,

    /// Enable verbose logging
    #[arg(short, long)]
    verbose: bool,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let args = Args::parse();

    // Initialize logging
    if args.verbose {
        env_logger::Builder::from_default_env()
            .filter_level(log::LevelFilter::Debug)
            .init();
    } else {
        env_logger::Builder::from_default_env()
            .filter_level(log::LevelFilter::Info)
            .init();
    }

    let addr: SocketAddr = format!("{}:{}", args.host, args.port).parse()?;
    let config = ProxyConfig::new(addr, args.verbose);
    let server = ProxyServer::new(config);

    info!("Starting HTTP Proxy Server on http://{}", addr);
    info!("Verbose logging: {}", args.verbose);
    
    server.run().await?;
    
    Ok(())
}